<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="display" uri="/WEB-INF/tags/displaytag-12.tld"%>
<%@page import="com.opensymphony.module.sitemesh.Page"%>
<html>
<head>
<meta name="tab" content="payment" />
<meta name="leftbar-link" content="student-payment"/>
<meta name="decorator" content="DefaultLayout"/>
<link href="<s:url value="/webwork/jscalendar/calendar-blue.css" />" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<script type="text/javascript">

function doChange(){
 var payMode =	document.getElementById('paymentMode').value;
  if(payMode == 'Cash'){
     document.getElementById('chequeBankName').value = "";
     document.getElementById('bankBranch').value = "";
     document.getElementById('chequeNo').value = "";
  
    document.getElementById('chequeBankName').readOnly =true;
	document.getElementById('bankBranch').readOnly =true;
	document.getElementById('chequeNo').readOnly =true;
  }else{
    document.getElementById('chequeBankName').readOnly =false;
	document.getElementById('bankBranch').readOnly =false;
	document.getElementById('chequeNo').readOnly =false;
    }
}
 
function doSubmit(){
  if(validateForm())
  {
    
  }else{
   
  }
}
 
 function validateForm(){
   	
  var flag = 0;
  
  var errormsg="";
  
  var stuCode = document.getElementById('studentId').value;
  var payMode =	document.getElementById('paymentMode').value;
  var amount =	document.getElementById('amount').value;
  var bankNo =	document.getElementById('chequeBankName').value;
  var branch =	document.getElementById('bankBranch').value;
  var chNo =	document.getElementById('chequeNo').value;
  var payDate =	document.getElementById('paymentDateStr').value;
  
  // Cash Cheque
  if(amount == "" || trim(amount).length == 0)
  {
    flag = 1;
	errormsg = "Amount is required field \n";
  }
  
  if(payMode == 'Cheque'){
     if(bankNo =="" || trim(bankNo).length == 0){
	   flag = 1;
	   errormsg =errormsg +"Cheque Bank Name is required field\n";
	 }
	 if(branch =="" || trim(branch).length == 0){
	   flag = 1;
	   errormsg =errormsg+"Bank Branch is required field\n";
	   
	 }
	 if(chNo =="" || trim(chNo).length == 0){
	   flag = 1;
	   errormsg =errormsg +"Cheque No is required field \n";
	 }
	 
  }

  
   if(flag == 0)
   {
   		document.getElementById('studentForm').action="addStudentPayment.action";
		document.getElementById('studentForm').submit();

   }else{
      alert(errormsg);
      return false;
   }
 } 
 
 
 
	// Removes leading whitespaces
	function LTrim( value ) {
		
		var re = /\s*((\S+\s*)*)/;
		return value.replace(re, "$1");
		
	}

	// Removes ending whitespaces
	function RTrim( value ) {
		
		var re = /((\s*\S+)*)\s*/;
		return value.replace(re, "$1");
		
	}

	// Removes leading and ending whitespaces
	function trim( value ) {
		
		return LTrim(RTrim(value));
		
	}
   	

</script>
<span id="pageHeading">Add Student Payment<hr/></span>

<s:form name="studentForm" id="studentForm" action="/addStudentPayment.action" method="post">
<table>
<tr>
	<td>Student Code*</td>
	<td><s:textfield id="studentId" required="true" name="studentPayment.studentId" value="%{studentPayment.studentId}"/></td>
</tr>

<tr>
	<td>Payment for Level*</td>
	<td>
<s:select id="levelId" required="true" name="studentPayment.levelId" 
	list="#{'1':'1','2':'2','3':'3','4':'4','5':'5','6':'6','7':'7','8':'8'}" />
</td>
</tr>


<tr>
	<td>Payment Mode*</td>
	<td>
<s:select id="paymentMode" required="true" name="studentPayment.paymentMode" 
   list="#{'Cash': 'Cash','Cheque':'Cheque'}" onchange="javaScript:doChange();"/>
</td>
</tr>

<tr>
	<td>Amount</td>
	<td>
<s:textfield  id="amount" name="studentPayment.amount" value="%{studentPayment.amount}" />
</td>
</tr>

<tr>
	<td>Cheque Bank Name</td>
	<td>
<s:textfield id="chequeBankName" name="studentPayment.chequeBankName" value="%{studentPayment.chequeBankName}" />
</td>
</tr>

<tr>
	<td>Branch</td>
	<td>
<s:textfield id="bankBranch" name="studentPayment.bankBranch" value="%{studentPayment.bankBranch}" />
</td>
</tr>

<tr>
	<td>Cheque Number</td>
	<td>
<s:textfield id="chequeNo" name="studentPayment.chequeNo" value="%{studentPayment.chequeNo}" />
</td>
</tr>

<tr>
	<td>Cheque Date</td>
	<td>
<s:datepicker id="chequeDateStr" name="chequeDateStr" value="%{chequeDateStr}"  maxLength = "10" 
	size="16" format = "%d-%m-%Y" /> 

</td>
</tr>
<tr>
<td>Payment Date*</td>
	<td>

<s:datepicker id="paymentDateStr" name="paymentDateStr" value="%{paymentDateStr}"  maxLength = "10" 
	size="16" format = "%d-%m-%Y" /> 


</td>
</tr>
<tr>
<td>Payment Remarks</td>
	<td>
<s:textfield  id="remarks"  name="studentPayment.remarks" value="%{studentPayment.remarks}" />
</td>
</tr>
 

<tr>
	<td colspan="4" align="center">
	 <A class="orange" style="cursor:pointer;" onclick="javascript:doSubmit();"> Add </A>
	</td>
</tr>

</table>

<p>

</s:form>

<script type="text/javascript">
 
  if(document.forms[0].studentId.value.length > 0 ){
     document.getElementById('studentId').readOnly =true;
  }
   var payMode =	document.getElementById('paymentMode').value;
  if(payMode == 'Cash'){
    document.getElementById('chequeBankName').readOnly =true;
	document.getElementById('bankBranch').readOnly =true;
	document.getElementById('chequeNo').readOnly =true;
  }

</script>
  </body>
</html>
